/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 15:12:58
 * @FilePath: \bg-vben\src\api\message\admin\message\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type { MessageInputDto, MessageOutputDto, MessageReceiverOutputDto } from './model';

import type { ErrorMessageMode, PageData } from '#/request';

import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** 管理-消息URL枚举 */
enum Api {
  /** 读取消息 */
  Read = '/api/admin/message/read',
  /** 读取消息接收者 */
  ReadReceiver = '/api/admin/message/readReceiver',
  /** 新增消息 */
  Create = '/api/admin/message/create',
  /** 更新消息 */
  Update = '/api/admin/message/update',
  /** 删除消息 */
  Delete = '/api/admin/message/delete',
  /** 发送消息 */
  Send = '/api/admin/message/send',
}

/**
 * 读取消息
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readMessages(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<MessageOutputDto>>(
    {
      url: Api.Read,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 读取消息接收者
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readMessageReceivers(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<MessageReceiverOutputDto>>(
    {
      url: Api.ReadReceiver,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 新增消息
 * @param dtos 消息DTO
 * @param mode 错误消息模型
 */
export function createMessages(dtos: MessageInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Create,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 更新消息
 * @param dtos 消息DTO
 * @param mode 错误消息模型
 */
export function updateMessages(dtos: MessageInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Update,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 删除消息
 * @param ids 消息编号
 * @param mode 错误消息模型
 */
export function deleteMessages(ids: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Delete,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 发送消息
 * @param ids 消息编号
 * @param mode 错误消息模型
 */
export function sendMessages(ids: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Send,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
